package com.example.home.loveDonation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.loveDonation.bean.CaringwelfareBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class CaringwelfareAdapter extends PagerAdapter {
    private Context context;
    private List<CaringwelfareBean.DataBean> list;

    public CaringwelfareAdapter(Context context, List<CaringwelfareBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View itemView = inflater.inflate(R.layout.view_pager_item, container, false);
        ImageView imageView = itemView.findViewById(R.id.imageView);

        CaringwelfareBean.DataBean item = list.get(position);
        Glide.with(context).load(ip + item.getImgUrl()).into(imageView);

        /*
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DetailActivity.class);
                intent.putExtra("car_id",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });*/


        container.addView(itemView);

        return itemView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }
}
